/**
 * 提现申请管理初始化
 */
var WithdrawApply = {
    id: "WithdrawApplyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
WithdrawApply.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        	{title: '帐号', field: 'accountNo', visible: true, align: 'center', valign: 'middle'},
        	{title: '账户名', field: 'accountName', visible: true, align: 'center', valign: 'middle'},
            {title: '订单号', field: 'outTradeNo', visible: true, align: 'center', valign: 'middle'},
            {title: '申请日期', field: 'applyDate', visible: true, align: 'center', valign: 'middle'},
            {title: '提现金额', field: 'amount', visible: true, align: 'center', valign: 'middle',formatter:"amountFormatter"},
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter:"statusFormatter"},
            {title: '手续费', field: 'chargeFee', visible: true, align: 'center', valign: 'middle',formatter:"amountFormatter"},
            {title: '审核时间', field: 'auditDate', visible: true, align: 'center', valign: 'middle'},
            {title: '审核描述', field: 'auditDesc', visible: true, align: 'center', valign: 'middle'}
    ];
};

//0-提交审核中 1-已审核 2-审核失败,3-打款中，4-打款成功，5-打款失败
function statusFormatter(value, row, index){
	if (value == 0) {
		return '提交审核中';
	} else if(value == 1) {
		return '已审核';
	}else if(value == 2) {
		return '审核失败';
	}else if(value == 3) {
		return '打款中';
	}else if(value == 4) {
		return '打款成功';
	}else if(value == 5) {
		return '打款失败';
	}
}

/**
 * 金额格式化
 * @param value
 * @param row
 * @param index
 * @returns
 */
function amountFormatter(value, row, index){
	if(value==null || value==''){
		return "0.00";
	}else{
		return parseFloat(value).toFixed(2);
	}
}


/**
 * 检查是否选中
 */
WithdrawApply.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        WithdrawApply.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加提现申请
 */
WithdrawApply.openAddWithdrawApply = function () {
    var index = layer.open({
        type: 2,
        title: '添加提现申请',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/withdrawApply/withdrawApply_add'
    });
    this.layerIndex = index;
};

/**
 * 审核
 */
WithdrawApply.openAuditApply = function () {
	if (this.check()) {
    var index = layer.open({
        type: 2,
        title: '提现审核',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/withdrawApply/withdrawApply_audit/'+ WithdrawApply.seItem.id
    });
    	this.layerIndex = index;
	}
};



/**
 * 打开查看提现申请详情
 */
WithdrawApply.openWithdrawApplyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '提现申请详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/withdrawApply/withdrawApply_update/' + WithdrawApply.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除提现申请
 */
WithdrawApply.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/withdrawApply/delete", function (data) {
            Feng.success("删除成功!");
            WithdrawApply.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("withdrawApplyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 打款
 */
WithdrawApply.remittance = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/withdrawApply/remittance", function (data) {
            Feng.success("打款成功!");
            WithdrawApply.table.refresh();
        }, function (data) {
            Feng.error("打款失败!" + data.responseJSON.message + "!");
        });
        ajax.set("withdrawApplyId",this.seItem.id);
        ajax.start();
    }
};



/**
 * 查询参数
 */
WithdrawApply.formParams = function() {
    var queryData = {};
    queryData['accountName'] = $("#accountName").val();
    queryData['accountNo'] = $("#accountNo").val();
    queryData['outTradeNo'] = $("#outTradeNo").val();
    queryData['status'] = $("#status").val();

    return queryData;
}

/**
 * 查询提现帐号列表
 */
WithdrawApply.search = function () {
	WithdrawApply.table.refresh({query: WithdrawApply.formParams()});
};


$(function () {
    var defaultColunms = WithdrawApply.initColumn();
    var table = new BSTable(WithdrawApply.id, "/withdrawApply/list", defaultColunms);
    table.setPaginationType("server");//服务器端分页
    table.setQueryParams(WithdrawApply.formParams());
    WithdrawApply.table = table.init();
});
